<?php
include_once('./header.php');
?>
				<div id="corps-grand">
					<div id="tete-corps-grand"></div>
					<div id="milieu-corps-grand"><?php
						/*
						Affiche le nom du serveur, son statut (en ligne ou non) grace à  son id 13 = Cobalt
						*/
						$Census = file_get_contents('http://census.soe.com/get/ps2:v2/map/?world_id=13&zone_ids=2,4,6,8');
						$mapData = json_decode($Census, true);
						
						if($mapData['returned'] == 0 || !isset($mapData['returned'])){
							echo 'ERREUR';
						} else {
							$page = 'http://census.soe.com/json/get/ps2/world/?world_id=13';
							$census = file_get_contents($page);
							$parsed_json = json_decode($census);

							$serveur = $parsed_json->{'world_list'}[0];
							$nom_serveur = $serveur->{'name'}->{'fr'};
							
							if ($serveur->{'state'} == 'locked') {$statut = '<span style="color:yellow;">Maintenance</span>';}
							elseif ($serveur->{'state'} == 'online') {$statut = '<span style="color:green;">En ligne</span>';}						
							elseif ($serveur->{'state'} == 'offline') {$statut = '<span style="color:red;">Hors ligne</span>';}
							else {$statut = '<span style="color:yellow;">Inconnu</span>';}
							
							echo '<b>' . $nom_serveur . ':</b> ' . $statut . '<br><br>';
						
							$Continents = array(
								'Indar'   => 0,  
								'Hossin'  => 2, 
								'Amerish' => 1, 
								'Esamir'  => 3
							);
							
							for($map = 0; $map <= 3; $map++){
								$NC = array();
								$VS = array();
								$TR = array();
								foreach($mapData['map_list'][$map]['Regions']['Row'] as $hex){
									if($hex['RowData']['FactionId'] == 1){
										$VS[] = 'VS';
									} elseif($hex['RowData']['FactionId'] == 2){
										$NC[] = 'NC';
									} elseif($hex['RowData']['FactionId'] == 3){
										$TR[] = 'TR';
									}
								}
								if(count($VS) == 0 && count($TR) == 0 && count($NC) == 0){
									$ContinentInfo = 'Inconnu';
								} else {
									if(count($VS) == 0 && count($TR) == 0){
										$ContinentInfo = '<span style="color:red;">Verrouillé</span>  par <span style="color:blue;">le Nouveau Conglomérat</span>';
									} elseif(count($NC) == 0 && count($TR) == 0){
										$ContinentInfo = '<span style="color:red;">Verrouillé</span>  par <span style="color:purple;">la Souveraineté Vanu</span>';
									} elseif(count($NC) == 0 && count($VS) == 0){
										$ContinentInfo = '<span style="color:red;">Verrouillé</span> par <span style="color:darkred;">la République Terran</span>';
									} else {
										$ContinentInfo = '<span style="color:green;">Déverrouillé</span>';
									}
								}
								echo '<b>' . array_search($map, $Continents) . '</b> est ' . $ContinentInfo .  '<br>';
							}
						}
					?>
					</div>
					<div id="pied-corps-grand"></div>
				</div>
				<br class="clear" /> 
<?php
include_once('./footer.php');
?>